
from qtpy import QtCore
from qtpy import QtWidgets
from qtpy import QtGui



class ImageSlider(QtWidgets.QDialog):

    valueChanged = QtCore.Signal(int)

    def __init__(self, parent=None) -> None:
        super().__init__(parent)

        self.hlayout = QtWidgets.QHBoxLayout()

        self.hSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal,self)
        self.hSlider.setSingleStep(10)
        self.hSlider.setMaximum(0)

        self.line_edit = QtWidgets.QLineEdit(self)
        self.line_edit.setFixedWidth(50)
        self.line_edit.setText(str(self.hSlider.value()))

        self.hlayout.addWidget(self.hSlider)
        self.hlayout.addWidget(self.line_edit)
        self.setLayout(self.hlayout)

        self.hSlider.valueChanged.connect(self.hSliderValueChange)
        self.line_edit.returnPressed.connect(self.lineEditReturnPressed)

    def hSliderValueChange(self, num):

        self.line_edit.setText(str(num))
        self.valueChanged.emit(num)

    def lineEditReturnPressed(self):
        self.hSlider.setValue(int(self.line_edit.text()))

    def setHSliderValue(self, value):
        if value == self.hSlider.value():
            self.valueChanged.emit(value)
        else:
            self.hSlider.setValue(value)

    def setMaximum(self, value):
        self.hSlider.setMaximum(value)




if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ex = ImageSlider()
    ex.show()
    sys.exit(app.exec_())
